# -*- coding: UTF-8 -*-
# version 1.0
# IP子网
from mxsoftpy import View
from index import _
from server.common.NetworkManage.IpAM.IpSubnet import IpSubnetServer


class RequestBase(View):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.request.POST['company'] = self.request.company


class IpSubnetSet(RequestBase):

    def post(self):
        """
        添加IP子网
        """
        try:
            return _('新增成功'), {'id': IpSubnetServer().create(**self.request.POST)}
        except Exception as e:
            return str(e)


class IpSubnetDelete(RequestBase):

    def post(self):
        """
        删除IP子网
        """
        return _('删除成功'), IpSubnetServer().delete(**self.request.POST)


class IpSubnetIgnore(RequestBase):

    def post(self):
        """
        忽略IP子网
        :return:
        """
        return _('忽略成功'), IpSubnetServer().ignore(**self.request.POST)


class IpCount(RequestBase):

    def post(self):
        """
        IP数量统计
        :return:
        """
        return '', IpSubnetServer().IpCount(**self.request.POST)


class SubnetRecovery(RequestBase):

    def post(self):
        """
        恢复子网
        :return:
        """
        return '', IpSubnetServer().SubnetRecovery(**self.request.POST)


class ScanningSet(RequestBase):

    def post(self):
        """
        自动扫描设置
        :return:
        """
        return '', IpSubnetServer().ScanningSet(**self.request.POST)


class Scanning(RequestBase):

    def post(self):
        """
        扫描
        :return:
        """
        return '', IpSubnetServer().Scanning(**self.request.POST)


class FindIp(RequestBase):

    def post(self):
        """
        发现Ip
        :return:
        """
        return '', IpSubnetServer().FindIp(**self.request.POST)
